import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/ls_login.vue'
import Home from '../components/ls_home.vue'
import Users from '../components/user/ls_user.vue'
import Rights from '../components/power/ls_rights.vue'
import Roles from '../components/power/ls_roles.vue'
import Categories from '../components/goods/ls_cate.vue'
import Params from '../components/goods/ls_params.vue'
import Goods from '../components/goods/ls_goods.vue'
import Add from '../components/goods/ls_add.vue'
import Orders from '../components/order/ls_orders.vue'
import Reports from '../components/projectReport/ls_reports.vue'

Vue.use(VueRouter)

const router = new VueRouter({
	routes: [
		{
			path: '/',
			redirect: '/Login',
		},
		{
			path: '/Login',
			component: Login,
		},
		{
			path: '/Home',
			component: Home,
			redirect: '/Users',
			children: [
				{
					path: '/Users',
					component: Users,
				},
				{
					path: '/Rights',
					component: Rights,
				},
				{
					path: '/Roles',
					component: Roles,
				},
				{
					path: '/Categories',
					component: Categories,
				},
				{
					path: '/Params',
					component: Params,
				},
				{
					path: '/Goods',
					component: Goods,
				},
				{
					path: '/goods/add',
					component: Add,
				},
				{
					path: '/Orders',
					component: Orders,
				},
				{
					path: '/Reports',
					component: Reports,
				},
			],
		},
	],
})
// 挂载路由守卫
router.beforeEach((to, from, next) => {
	if (to.path == '/Login') return next()
	const tokenStr = window.sessionStorage.getItem('token')
	if (!tokenStr) return next('/Login')
	next()
})
export default router
